package com.ddwl.gate.controller;


import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.gate.service.RegionService;
import com.ddwl.schema.bo.gate.RegionBo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.gate.RegionVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Fu Zhaohui
 * @date 2017/1/3
 */
@Api(tags = "行政区域服务")
@RequestMapping("/region")
@RestController
public class RegionController extends BaseController {

    @Autowired
    private RegionService regionService;


    @GetMapping("/get")
    @ApiOperation("地址获取地址详情")
    public RestVo<RegionVo> geoKey(@RequestParam String id) {
        return RestVo.ok(regionService.getRegionById(id));
    }

    @PostMapping("/cityId")
    @ApiOperation("获取城市ID")
    public RestVo<String> getCityId(@RequestBody RegionBo bo) {
        return RestVo.ok(regionService.getCityId(bo.getProvinceName(), bo.getCity()));
    }

    /**
     * 获取地址详情列表
     * @param ids
     * @return
     */
    @GetMapping("/listByIds")
    @ApiOperation("地址获取地址详情列表")
    RestVo<List<RegionVo>> listLegionByIds(@RequestParam("ids") String ids){
        return RestVo.ok(regionService.listByIds(ids));
    }

    @GetMapping
    @Auth(required = false)
    @ApiOperation("获取行政规划信息")
    public RestVo<List<RegionVo>> getRegion(@RequestParam(required = false) String province,
                                            @RequestParam(required = false) String city,
                                            @RequestParam(required = false) String keyword) {
        return RestVo.ok(regionService.getRegion(province, city, keyword));
    }

    @GetMapping("/all")
    @Auth(required = false)
    @ApiOperation("获取行政规划信息（树型）")
    public RestVo<List<RegionVo>> getAllRegion() {
        return RestVo.ok(regionService.getAllRegion());
    }

    @GetMapping("/geo")
    //@Auth(product = {BaseEnum.ProductEnum.CONSOLE,BaseEnum.ProductEnum.API})
    @ApiOperation("地址获取经纬度")
    public RestVo<Object> geoLoc(@RequestParam(required = false) String city, @RequestParam String address) {
        return RestVo.ok(regionService.geoLoc(city, address));
    }

    @GetMapping("/reGeo")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE,BaseEnum.ProductEnum.API,BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE, BaseEnum.ProductEnum.BYTE_DANCE})
    @ApiOperation("根据经纬度获取地址 经度在前, ','分割")
    public RestVo<Object> geoReLoc(@RequestParam(required = false) Integer radius, @RequestParam String location) {
        return RestVo.ok(regionService.geoReLoc(radius, location));
    }

    @GetMapping("/geo/key")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    @ApiOperation("地址获取AMapKey")
    public RestVo<String> geoKey() {
        return RestVo.ok(regionService.getAmapKey());
    }

    @PostMapping("/findByBo")
    //@Auth(product = {BaseEnum.ProductEnum.API})
    @ApiOperation("根据省市区地址名称查询")
    public RestVo<RegionVo> findByBo(@RequestBody RegionBo regionBo) {
        return RestVo.ok(regionService.findByBo(regionBo));
    }
}
